﻿@{
    string guid = Html.Guid();
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
}
<script src="~/Incs/UEditor/ueditor.forAdmin.config.js" type="text/javascript"></script>
<script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
<div class="main">
    <form method="post" id="_form" class="form ui-validForm " data-source="@Model"  data-validate-params="beforeSubmit:'BeforeSubmit',tipsStyle:1">
        <div class="tabcontent" data-tab-params="tabName:'基础设置'">
            <div class="form-group">
                <label class="control-label">栏目名称</label>
                <div class="controls">
                    <input name="Name" id="Name" type="text" maxlength="50" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请填写栏目名称！'">
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label">栏目类型</label>
                <div class="controls">
                    <select name="ColumnType" id="ColumnType" class="form-control form-control-sm  ui-show-hide" @*onchange="ChangeType(this.options[this.options.selectedIndex].value)"*@>
                        <option value="0" hideObjs=".box_is_final,.box_tableId,.box_dir,.box_template_detail,.publishSet-box,.box_zdy_url">首页</option>
                        <option value="1" showObjs=".box_is_final,.box_tableId,.box_dir,.box_template_detail,.box_template,.publishSet-box" selected>信息页</option>
                        <option value="2" hideObjs=".box_tableId,.box_template_detail,.publishSet-box" showObjs=".box_is_final,.box_dir,.box_template">单页面</option>
                        <option value="3" hideObjs=".box-httpcache,.box_dir,.box_template,.box_tableId,.publishSet-box" showObjs=".box_zdy_url">自定义链接</option>
                    </select>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group box_is_final">
                <label class="control-label">是否最终栏目</label>
                <div class="controls">
                    <label class="radio-inline">
                        <input type="radio" name="IsFinal" id="IsFinal" value="1" checked class="ui-edit-readonly">是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="IsFinal" id="IsFinal" value="0" class="ui-edit-readonly">否
                    </label>
                    <span class="help-block">如果当前栏目有子级栏目，请设置为否</span>
                </div>
            </div>

            <div class="form-group box_tableId">
                <label class="control-label">栏目信息表</label>
                <div class="controls form-inline">
                    <div class="input-group">
                        <select name="TableId" id="TableId" class="form-control form-control-sm ui-convertData" data-validate="dataType:'*',nullMsg:'请选择信息表！',ignoreHidden:true" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","InfoTable")',textField:'Remark'">
                            <option value="">请点击右侧按钮选择信息表</option>
                        </select>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default ui-dialog" data-custom-params="title:'选择信息表',url:'@Url.ActionUrl("Select","InfoTable")?siteid=@ViewBag.CurrentSiteId&objname=#TableId',width:'700px',height:'90%',target:'_self'">选择信息表</button>
                        </span>
                    </div>
                    <span class="help-block" id="_ValidateTips_TableId"></span>
                </div>
            </div>


            <div class="form-group">
                <label class="control-label">栏目缓存方案</label>
                <div class="controls form-inline">
                    <div class="input-group">
                        <select name="HttpcacheSolutionId" id="HttpcacheSolutionId" class="form-control form-control-sm ui-convertData" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","HttpCacheSolution")',textField:'Name'">
                            <option value="0">不缓存</option>
                        </select>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default ui-dialog" data-custom-params="title:'选择http缓存方案',url:'@Url.ActionUrl("Select","HttpCacheSolution")?objname=#HttpcacheSolutionId',width:'700px',height:'90%',target:'_self'">选择方案</button>
                        </span>
                    </div>
                    <span class="help-block" id="_ValidateTips_HttpcacheSolutionId">http缓存方案请到系统>系统配置>http缓存方案中设置</span>
                </div>
            </div>

            <div class="form-group box_dir">
                <label class="control-label">访问路径</label>
                <div class="controls form-inline">
                    <div class="input-group">
                        <input type="text" maxlength="200" id="Path" name="Path" class="form-control form-control-sm" data-validate="dataType:'path',nullMsg:'请填写访问路径!',errorMsg:'路径格式错误,节点不能包含特殊字段，也不能为纯数字',ignoreHidden:true">
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default" onclick="SetDir()">生成</button>
                        </span>
                    </div>
                    <span class="help-block" id="_ValidateTips_Path">前台的访问路径，如：news，可以填写多级目录，如：news/company</span>
                </div>
            </div>

            <div class="box_template" data-source="@ViewBag.TemplateSet">
                <div class="box_pc">
                    <div class="form-group box_template">
                        <label class="control-label">栏目模板</label>
                        <div class="controls form-inline">
                            <div class="input-group">
                                <input type="text" placeholder="栏目页的模板文件" maxlength="100" id="template_set_Template" name="template_set_Template" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请选择栏目模板',ignoreHidden:true" />
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-default ui-dialog" data-custom-params="title:'选择栏目模板',url:'@Url.ActionUrl("Select","TemplateManager")?objname=#template_set_Template',width:'650px',height:'95%',target:'self'">选择</button>
                                </span>
                            </div>
                            <span class="help-block" id="_ValidateTips_template_set_Template">模板只能选择.cshtml后缀的文件</span>
                        </div>
                    </div>

                    <div class="form-group box_template_detail">
                        <label class="control-label">内容页模版</label>
                        <div class="controls form-inline">
                            <div class="input-group">
                                <input type="text" placeholder="内容页的模板文件" maxlength="100" id="template_set_TemplateDetail" name="template_set_TemplateDetail" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请选择内容页模板',ignoreHidden:true" />
                                <span class="input-group-btn">
                                    <button type="button" class="btn  btn-default ui-dialog" data-custom-params="title:'选择内容页模板',url:'@Url.ActionUrl("Select","TemplateManager")?objname=#template_set_TemplateDetail',width:'650px',height:'95%',target:'self'">选择</button>
                                </span>
                            </div>
                            <span class="help-block" id="_ValidateTips_template_set_TemplateDetail">模板只能选择.cshtml后缀的文件</span>
                        </div>
                    </div>

                </div>
            </div>

            <script type="text/javascript">

                //从父级获取的参数
                var tableId = "@ViewBag.TableId";
                var ColumnType = "@ViewBag.ColumnType";
                if (tableId != "") {
                    $("#TableId").ConvertData({ ids: tableId, isFormBind: true });
                }
                if (ColumnType != "" && ColumnType != "0") {
                    $("#ColumnType").val(ColumnType);
                }
            </script>


            <div class="form-group">
                <label class="control-label">目标窗口</label>
                <div class="controls radio">
                    <label class="radio-inline">
                        <input type="radio" name="Target" id="Target" checked value="_self">本窗口
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="Target" id="Target" value="_blank">新窗口
                    </label>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label">自定义链接</label>
                <div class="controls">
                    <input type="text" maxlength="100" id="ZdyUrl" name="ZdyUrl" class="form-control form-control-sm" />
                    <span class="help-block">当栏目需要指向其他页面，可通过自定义链接实现</span>
                </div>
            </div>


            <div class="form-group box_show">
                <label class="control-label">是否显示</label>
                <div class="controls">
                    <label class="radio-inline">
                        <input type="radio" name="Show" id="Show" checked value="1">显示
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="Show" id="Show" value="0">隐藏
                    </label>
                    <span class="help-block"></span>
                </div>
            </div>

            @{
                IEnumerable<dynamic> fieldData = Html.GetFieldList("pa_column", action, user);
                string beforeSubmitJs = "";
                var data = new ViewDataDictionary();
                data.Add("from", "admin");
                data.Add("guid", guid);
                data.Add("currentUser", ViewBag.CurrentUser);
                data.Add("fieldPrefix", "");
                data.Add("i", 0);
                int i = 0;
                if (fieldData != null)
                {
                    foreach (var row in fieldData)
                    {
                        data["i"] = i;
                        beforeSubmitJs += row.BeforeSubmitJs;
                        Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                        i++;
                    }
                }
            }
            <div class="form-group">
                <label class="control-label">序号</label>
                <div class="controls controls-xs">
                    <input name="Xuhao" id="Xuhao" type="text" maxlength="5" class="ui-queryString form-control form-control-xs" value="1" data-validate="dataType:'numeric',nullMsg:'请填写序号！',errorMsg:'序号只能填写数字！'">
                    <span class="help-block"></span>
                </div>
            </div>
        </div>

        <div class="tabcontent" data-tab-params="tabName:'内容设置'">
            <div id="_seoBox" data-source="@ViewBag.SeoSet">
                <div class="form-group">
                    <label class="control-label">seo标题</label>
                    <div class="controls">
                        <input name="seo_set_Title" id="seo_set_Title" type="text" maxlength="50" class="form-control">
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">seo关键词</label>
                    <div class="controls">
                        <input name="seo_set_Keywords" id="seo_set_Keywords" type="text" maxlength="150" class="form-control">
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">seo描述</label>
                    <div class="controls">
                        <textarea id="seo_set_Description" name="seo_set_Description" class="form-control" style="height:60px;"></textarea>
                        <span class="help-block"></span>
                    </div>
                </div>
                <input type="hidden" id="_seoData" value="" />
            </div>
            <div id="_contentSetBox" data-source="@ViewBag.ContentSet">
                @{
                    fieldData = Html.GetFieldList("pa_column_content_set", action, user);
                    data = new ViewDataDictionary();
                    data.Add("from", "admin");
                    data.Add("guid", guid);
                    data.Add("currentUser", ViewBag.CurrentUser);
                    data.Add("fieldPrefix", "content_set_");
                    data.Add("detailId", ViewBag.ContentSetId??0);
                    data.Add("i", 0);
                    i = 0;
                    if (fieldData != null)
                    {
                        foreach (var row in fieldData)
                        {
                            data["i"] = i;
                            beforeSubmitJs += row.BeforeSubmitJs;
                            Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                            i++;
                        }
                    }
                }
            </div>
        </div>

        <div class="submit-footerbar">
            <label class="control-label"></label>
            <div class="controls">
                <input type="hidden" name="Guid" id="Guid" value="@guid" />
                <input type="hidden" name="Id" id="Id" />
                <input type="hidden" name="SiteId" id="SiteId" value="@ViewBag.CurrentSiteId" />
                <input type="hidden" name="Level" id="Level" value="1" />
                <input type="hidden" name="ParentId" id="ParentId" value="@ViewBag.ParentId" />
                <button type="button" class="btn  btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',callBack:'PostRefreshBack'">提交</button> 
                <button type="button" class="btn btn-default ui-closeDialog">关闭</button>
            </div>
        </div>

    </form>
</div>
<script src="/Areas/Admin/Js/pinyin.js" type="text/javascript"></script>
<script type="text/javascript">
    $(".tabcontent").InitTab();
    var $name = $("#Name");
    function BeforeSubmit() {
        BeforePost();
        @Html.Raw(beforeSubmitJs)
        return true;
    }

    //访问路径，格式：abc/cbd
    $.ValidateDataType.path = function (gets, obj, curform) {
        if (gets=="") { return false;}
        var arrPath = gets.split("/");
        var length = arrPath.length;
        for (i = 0; i < length; i++) {
            if (arrPath[i].Trim()=="") {
                continue;
            }
            if (!IsStr(arrPath[i])) {
                return "路径节点只能由字母，数据或下划线组成！";
            }
            else if (IsInt(arrPath[i])) {
                return "路径节点不能为纯数字！";
            }
        }
        arrPath = arrPath.filter(function (n) { return n; });
        obj.val(arrPath.join("/"));
        var sysPath = new Array("views", "upload", "templates", "js", "incs", "entities", "css", "config", "bin", "areas", "appplugins", "appdata", "member", "admin");
        if (sysPath.Contains(gets.Trim().toLowerCase()))
        {
            return gets+"为系统路径，请更换一个路径！";
        }
        return true;
    }

    var $path = $("#Path");
    var $tabhead = $(".tabhead");
    var $table_id = $("#TableId");

    var $publish_set_box = $("#_publishSet");
    var $template_set_template = $("#template_set_Template");
    var $template_set_template_detail = $("#template_set_TemplateDetail");

    var $thetype = $("#ColumnType");
    var $parentId = $("#ParentId");
    var parentId = Request("parentId");
    var $zdyUrl = $("#ZdyUrl");
    var id = Request("id");
    if (id != "") {
        //绑定数据
        $("#_form").FormBind({ dataSourceFrom: "attr" });
        parentId = $parentId.val();
        //ChangeType($thetype.val());

        $("input[name='IsFinal']").attr("disabled", "disabled");

        $("#_seoBox").FormBind({ bindId: false, fieldPrefix: "seo_set_", dataSourceFrom: "attr" });
        $("#_contentSetBox").FormBind({ bindId: false, fieldPrefix: "content_set_", dataSourceFrom: "attr" });
        if (parentId != "0") {
            $thetype.children().eq(0).remove();
            //ChangeType($thetype.val());
        }
    }
    //放外面，因为添加子级时可继承父级的设置
    $(".box_template").FormBind({ bindId: false, fieldPrefix: "template_set_", dataSourceFrom: "attr" });

    function BeforePost() {
        $name.val($name.val().Trim());
        var columnType = $thetype.val();
        if (columnType == "0") {
            $table_id.val("0");
            $path.val("");
            $template_set_template_detail.val("");
            $zdyUrl.val("");
        }
        else if (columnType == "1") {

        }
        else if (columnType == "2") {
            ;
            $table_id.val("0");
            $template_set_template_detail.val("");

        }
        else if (columnType == "3") {
            $table_id.val("0");
            $template_set_template.val("");
            $template_set_template_detail.val("");
        }
    }

    function SetDir() {
        var columnName = $("#Name").val();
        if (columnName != "") {
            $path.val(ToPY(columnName, 50));
        }
        else {
            Alert("请先填写栏目名称！");
            $("#Name").focus();
        }
    }
</script>
